package org.dbstar.scheduler.ldap;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dbstar.scheduler.beans.OperateType;
import org.dbstar.scheduler.control.OperateController;
import org.dbstar.scheduler.control.exception.DaoException;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;


/**
 * 用户退出登录成功后的处理
 * 
 * @author 代波
 * @since 1.0.0
 * @version 1.0.0
 * @date 2012-6-5
 */
public class SchedulerLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
	private final OperateController operateController;

	public SchedulerLogoutSuccessHandler(OperateController operateController) {
		super();
		this.operateController = operateController;
	}

	@Override
	public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		super.onLogoutSuccess(request, response, authentication);
		try {
			operateController.operate(authentication.getName(), OperateType.logout, null);
		} catch (DaoException e) {
			throw new ServletException(e);
		}
	}
}
